<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Blog</title>
    <meta name="generator" content="VuePress 1.9.7">
    <link rel="icon" href="/blog/favicon.ico">
    <meta name="description" content="MyBlog">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/blog/assets/css/0.styles.61da7a09.css" as="style"><link rel="preload" href="/blog/assets/js/app.c8bfb5c3.js" as="script"><link rel="preload" href="/blog/assets/js/3.08e74d92.js" as="script"><link rel="preload" href="/blog/assets/js/1.f96517fa.js" as="script"><link rel="preload" href="/blog/assets/js/20.5d2b0628.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.14d8e5c7.js"><link rel="prefetch" href="/blog/assets/js/11.a1a32059.js"><link rel="prefetch" href="/blog/assets/js/12.83c03cbb.js"><link rel="prefetch" href="/blog/assets/js/13.46ffbb28.js"><link rel="prefetch" href="/blog/assets/js/14.f20a4faf.js"><link rel="prefetch" href="/blog/assets/js/15.30235eae.js"><link rel="prefetch" href="/blog/assets/js/16.261be55c.js"><link rel="prefetch" href="/blog/assets/js/17.d7282b69.js"><link rel="prefetch" href="/blog/assets/js/18.e8bca3cd.js"><link rel="prefetch" href="/blog/assets/js/19.663ba2bd.js"><link rel="prefetch" href="/blog/assets/js/21.e9d43c16.js"><link rel="prefetch" href="/blog/assets/js/4.6ccf2801.js"><link rel="prefetch" href="/blog/assets/js/5.d9c29fca.js"><link rel="prefetch" href="/blog/assets/js/6.510ee365.js"><link rel="prefetch" href="/blog/assets/js/7.79ac4d06.js"><link rel="prefetch" href="/blog/assets/js/8.ddfc50a4.js"><link rel="prefetch" href="/blog/assets/js/9.0724da36.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.61da7a09.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-7dd95ae2><div data-v-7dd95ae2><div class="password-shadow password-wrapper-out" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88>Blog</h3> <p class="description" data-v-59e6cb88>MyBlog</p> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>Brod-Roy</span>
          
        <!---->
        2022
      </a></span></div></div> <div class="hide" data-v-7dd95ae2><header class="navbar" data-v-7dd95ae2><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><img src="/blog/logo.png" alt="Blog" class="logo"> <span class="site-name">Blog</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/frontEnd/" class="nav-link"><i class="undefined"></i>
  frontEnd
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间索引
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      相关内容
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/Brod_Roy" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-7dd95ae2></div> <aside class="sidebar" data-v-7dd95ae2><div class="personal-info-wrapper" data-v-1fad0c41 data-v-7dd95ae2><img src="/blog/avatar.jpg" alt="author-avatar" class="personal-img" data-v-1fad0c41> <h3 class="name" data-v-1fad0c41>
    Brod-Roy
  </h3> <div class="num" data-v-1fad0c41><div data-v-1fad0c41><h3 data-v-1fad0c41>1</h3> <h6 data-v-1fad0c41>Articles</h6></div> <div data-v-1fad0c41><h3 data-v-1fad0c41>2</h3> <h6 data-v-1fad0c41>Tags</h6></div></div> <ul class="social-links" data-v-1fad0c41></ul> <hr data-v-1fad0c41></div> <nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/frontEnd/" class="nav-link"><i class="undefined"></i>
  frontEnd
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间索引
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      相关内容
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/Brod_Roy" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-59e6cb88 data-v-7dd95ae2><h3 class="title" data-v-59e6cb88></h3> <!----> <label id="box" class="inputBox" data-v-59e6cb88><input type="password" value="" data-v-59e6cb88> <span data-v-59e6cb88>Konck! Knock!</span> <button data-v-59e6cb88>OK</button></label> <div class="footer" data-v-59e6cb88><span data-v-59e6cb88><i class="iconfont reco-theme" data-v-59e6cb88></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-59e6cb88>vuePress-theme-reco</a></span> <span data-v-59e6cb88><i class="iconfont reco-copyright" data-v-59e6cb88></i> <a data-v-59e6cb88><span data-v-59e6cb88>Brod-Roy</span>
          
        <!---->
        2022
      </a></span></div></div> <div data-v-7dd95ae2><div data-v-7dd95ae2><main class="page" style="padding-right:0;"><section style="display:;"><div class="page-title"><h1 class="title"></h1> <div data-v-8a445198><i class="iconfont reco-account" data-v-8a445198><span data-v-8a445198>Brod-Roy</span></i> <!----> <!----> <!----></div></div> <div class="theme-reco-content content__default"><p>---</p> <p>title: 基于uniapp(小程序)的前端接口封装方法</p> <p>date: 2022-11-17</p> <p>categories:</p> <p>- 前端学习</p> <p>tags:</p> <p>- uniapp</p> <p>---</p> <h1 id="基于uniapp-小程序-的前端接口封装方法"><a href="#基于uniapp-小程序-的前端接口封装方法" class="header-anchor">#</a> 基于uniapp(小程序)的前端接口封装方法</h1> <blockquote><p>本文将详细讲解封装思路，通过对接口请求进行封装，实现接口引入即用，减少了请求复杂的属性参数，更加关注数据与业务本身。</p></blockquote> <h2 id="config-请求地址及相关参数配置"><a href="#config-请求地址及相关参数配置" class="header-anchor">#</a> config - 请求地址及相关参数配置</h2> <blockquote><p>在 config 中配置好动态域名，对不同环境进行配置，方便前端开发时的调试与部署。</p></blockquote> <h3 id="develop-js-开发"><a href="#develop-js-开发" class="header-anchor">#</a> develop.js（开发）</h3> <blockquote><p>配置开发环境：有多个开发环境时，可以根据开发的需要切换到不同的接口进行调试，定义完后抛出。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> <span class="token constant">ENV_TYPE</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
	<span class="token comment">// baseUrl: 'https://120.120.120.1/', // 调试环境1</span>
    <span class="token comment">// baseUrl: 'https://120.120.120.2/', // 调试环境2</span>
    <span class="token comment">// baseUrl: 'https://120.120.120.3/', // 调试环境3</span>
    <span class="token literal-property property">baseUrl</span><span class="token operator">:</span> <span class="token string">'https://120.120.120.4/'</span><span class="token punctuation">,</span> <span class="token comment">// 调试环境4</span>
<span class="token punctuation">}</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token constant">ENV_TYPE</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h3 id="trial-js-体验"><a href="#trial-js-体验" class="header-anchor">#</a> trial.js（体验）</h3> <blockquote><p>配置体验版服务器的地址，小程序上必须先发布体验版再发布测试版</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> <span class="token constant">ENV_TYPE</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
	<span class="token literal-property property">baseUrl</span><span class="token operator">:</span> <span class="token string">'https://test.com/'</span><span class="token punctuation">,</span> <span class="token comment">// 体验服务器地址</span>
<span class="token punctuation">}</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token constant">ENV_TYPE</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="release-js-正式"><a href="#release-js-正式" class="header-anchor">#</a> release.js（正式）</h3> <blockquote><p>配置正式服务器地址</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">const</span> <span class="token constant">ENV_TYPE</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
	<span class="token literal-property property">baseUrl</span><span class="token operator">:</span> <span class="token string">'https://formal.com/'</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token constant">ENV_TYPE</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h3 id="urlconfig-js-判断当前环境"><a href="#urlconfig-js-判断当前环境" class="header-anchor">#</a> urlConfig.js（判断当前环境）</h3> <blockquote><blockquote><p>通过对环境的检测，判断当前所属的是什么环境，动态切入请求地址，减少上传时的操作步骤。</p></blockquote> <blockquote><p>现在我们需要了解的是如何知道当前所属的环境。由下文可知，我们可以基于 <code>process.env.ENV_PATH</code> 和 <code>uni.getAccountInfoSync()</code> 获取当前所属的环境动态配置</p></blockquote> <p><code>uni-app</code> 可通过 <strong><code>process.env.NODE_ENV</code></strong> 判断当前环境是开发环境还是生产环境。一般用于连接测试服务器或生产服务器的动态切换。</p> <ul><li>在 HBuilderX 中，点击“运行”编译出来的代码是开发环境，点击“发行”编译出来的代码是生产环境</li> <li>cli 模式下，是通行的编译环境处理方式。</li></ul> <p><strong><code>uni.getAccountInfoSync()</code></strong> 获取当前帐号信息，可以返回小程序的Appid。如果使用了微信小程序的云端插件，还可以反馈插件的id和版本</p> <ul><li><p>miniProgram 的结构:</p> <table><thead><tr><th>属性</th> <th>类型</th> <th>说明</th></tr></thead> <tbody><tr><td>appId</td> <td>string</td> <td>小程序 appId</td></tr> <tr><td>envVersion</td> <td>string</td> <td>小程序 当前环境版本：<code>develop</code>、<code>trial</code>、<code>release</code></td></tr> <tr><td>version</td> <td>string</td> <td>版本号</td></tr></tbody></table></li></ul> <blockquote><p>动态添加成功后，抛出 <code>baseUrl</code> 给接口文件引入</p></blockquote></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">/**
 * 配置动态化域名，外部js引用此文件process.env.NODE_ENV
 */</span>
<span class="token keyword">let</span> path <span class="token operator">=</span> process<span class="token punctuation">.</span>env<span class="token punctuation">.</span><span class="token constant">ENV_PATH</span> <span class="token operator">==</span> <span class="token keyword">undefined</span> <span class="token operator">?</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'../config/develop'</span><span class="token punctuation">)</span> <span class="token operator">:</span> <span class="token function">require</span><span class="token punctuation">(</span>process<span class="token punctuation">.</span>env<span class="token punctuation">.</span><span class="token constant">ENV_PATH</span><span class="token punctuation">)</span>

<span class="token comment">// #ifdef MP-WEIXIN</span>
<span class="token comment">// ---------------- 根据微信开发环境配置请求地址 --------------------</span>
<span class="token comment">// 获取当前帐号信息</span>
<span class="token keyword">const</span> accountInfo <span class="token operator">=</span> uni<span class="token punctuation">.</span><span class="token function">getAccountInfoSync</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>accountInfo<span class="token punctuation">)</span>
<span class="token comment">// env类型 develop:开发版、trial:体验版、release:正式版</span>
<span class="token keyword">const</span> envWx <span class="token operator">=</span> accountInfo<span class="token punctuation">.</span>miniProgram<span class="token punctuation">.</span>envVersion<span class="token punctuation">;</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>envWx <span class="token operator">===</span> <span class="token string">'release'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	path <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'../config/release.js'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>envWx <span class="token operator">===</span> <span class="token string">'trial'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	path <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'../config/trial.js'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span><span class="token punctuation">(</span>envWx <span class="token operator">===</span> <span class="token string">'develop'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	path <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'../config/develop.js'</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
<span class="token comment">// #endif</span>

<span class="token keyword">const</span> baseUrl <span class="token operator">=</span> path<span class="token punctuation">.</span>baseUrl
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
	baseUrl
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><h2 id="networking-接口请求配置"><a href="#networking-接口请求配置" class="header-anchor">#</a> networking - 接口请求配置</h2> <blockquote><p>在该文件内我们对接口请求进行封装，对请求方式简化，专注于数据和业务。</p></blockquote> <h3 id="networkrequestmanage-js"><a href="#networkrequestmanage-js" class="header-anchor">#</a> networkRequestManage.js</h3> <blockquote><p>对uniapp请求进行封装，设置登录请求和上传图片等公共请求接口。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">/**
 * 网络请求管理，二次封装
 */</span>

<span class="token comment">/** 请求信息格式
{
  apiName: 'url',
  params: {
    'key1': 'value1',
    'key1': 'value2',
  },
  success: e=&gt; {

  },
  fail: e=&gt; {

  }
} */</span>

<span class="token comment">// 状态码</span>
<span class="token keyword">import</span> hsCode <span class="token keyword">from</span> <span class="token string">'../config/statusCode.js'</span>
<span class="token comment">// 导入当前域名地址</span>
<span class="token keyword">import</span> urlConfig <span class="token keyword">from</span> <span class="token string">'@/config/urlConfig.js'</span>
<span class="token comment">// 导入缓存</span>
<span class="token keyword">import</span> storage <span class="token keyword">from</span> <span class="token string">&quot;@/config/storage.js&quot;</span>

<span class="token comment">// 调用超时的是时候，保存调取接口传入参数的参数</span>
<span class="token keyword">let</span> requestInfoData <span class="token operator">=</span> <span class="token string">''</span>
<span class="token keyword">let</span> requestMethod <span class="token operator">=</span> <span class="token string">''</span>

<span class="token comment">/**
 * 请求数据
 * @url: 请求路径
 * @params：请求参数(数据类型，对象)
 * method： post get
 * success：成功回调函数
 * fail：失败回调函数
 */</span>
<span class="token keyword">function</span> <span class="token function">request</span><span class="token punctuation">(</span><span class="token parameter">apiName<span class="token punctuation">,</span> params <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span> method<span class="token punctuation">,</span> success<span class="token punctuation">,</span> fail</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">const</span> token <span class="token operator">=</span> storage<span class="token punctuation">.</span><span class="token function">getToken</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
	<span class="token keyword">var</span> headersParam <span class="token operator">=</span> <span class="token punctuation">{</span>
		<span class="token string-property property">'X-Requested-With'</span><span class="token operator">:</span> <span class="token string">'XMLHttpRequest'</span><span class="token punctuation">,</span>
		<span class="token string-property property">&quot;Accept&quot;</span><span class="token operator">:</span> <span class="token string">&quot;application/json&quot;</span><span class="token punctuation">,</span>
		<span class="token string-property property">&quot;Content-Type&quot;</span><span class="token operator">:</span> <span class="token string">&quot;application/json; charset=UTF-8;&quot;</span><span class="token punctuation">,</span>
		<span class="token string-property property">&quot;Accept-Encoding&quot;</span><span class="token operator">:</span> <span class="token string">''</span>
	<span class="token punctuation">}</span>
	<span class="token comment">// token为空</span>
	<span class="token keyword">if</span> <span class="token punctuation">(</span>token <span class="token operator">!=</span> <span class="token string">''</span> <span class="token operator">||</span> token <span class="token operator">!=</span> <span class="token keyword">undefined</span> <span class="token operator">||</span> token <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		headersParam<span class="token punctuation">[</span><span class="token string">'Authorization'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token string">'Bearer '</span> <span class="token operator">+</span> token
	<span class="token punctuation">}</span>
	console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>urlConfig<span class="token punctuation">.</span>baseUrl <span class="token operator">+</span> apiName<span class="token punctuation">)</span>
	console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'请求参数----&gt;'</span> <span class="token operator">+</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>params<span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token comment">// 发送请求</span>
	uni<span class="token punctuation">.</span><span class="token function">request</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
		<span class="token literal-property property">url</span><span class="token operator">:</span> urlConfig<span class="token punctuation">.</span>baseUrl <span class="token operator">+</span> apiName<span class="token punctuation">,</span>
		<span class="token literal-property property">data</span><span class="token operator">:</span> params<span class="token punctuation">,</span>
		<span class="token literal-property property">header</span><span class="token operator">:</span> headersParam<span class="token punctuation">,</span>
		<span class="token literal-property property">method</span><span class="token operator">:</span> method<span class="token punctuation">,</span>
		<span class="token function-variable function">success</span><span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span> <span class="token punctuation">(</span>res<span class="token punctuation">.</span>data<span class="token punctuation">.</span>code <span class="token operator">===</span> hsCode<span class="token punctuation">.</span><span class="token constant">SUCCESS</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				success <span class="token operator">&amp;&amp;</span> <span class="token function">success</span><span class="token punctuation">(</span>res<span class="token punctuation">.</span>data<span class="token punctuation">)</span>
				<span class="token comment">// token过期</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>res<span class="token punctuation">.</span>data<span class="token punctuation">.</span>code <span class="token operator">===</span> hsCode<span class="token punctuation">.</span><span class="token constant">DENY</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>

			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				<span class="token keyword">if</span> <span class="token punctuation">(</span>fail<span class="token punctuation">)</span> <span class="token punctuation">{</span>
					<span class="token function">fail</span><span class="token punctuation">(</span>res<span class="token punctuation">.</span>data<span class="token punctuation">.</span>msg<span class="token punctuation">)</span>
				<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
					uni<span class="token punctuation">.</span><span class="token function">showToast</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
						<span class="token literal-property property">title</span><span class="token operator">:</span> res<span class="token punctuation">.</span>data<span class="token punctuation">.</span>msg<span class="token punctuation">,</span>
						<span class="token literal-property property">icon</span><span class="token operator">:</span> <span class="token string">'none'</span>
					<span class="token punctuation">}</span><span class="token punctuation">)</span>
				<span class="token punctuation">}</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">,</span>
		<span class="token function-variable function">fail</span><span class="token operator">:</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			fail <span class="token operator">&amp;&amp;</span> <span class="token function">fail</span><span class="token punctuation">(</span><span class="token string">'请检查网络'</span><span class="token punctuation">)</span>
		<span class="token punctuation">}</span><span class="token punctuation">,</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// 微信登录获取 sessionKey</span>
<span class="token comment">/**
 * 重新登录
 * @success： 成功回调函数
 * @params： 额外参数
 * @isAgin：超时重新请求当前数据(false不请求，true请求)
 */</span>
<span class="token keyword">function</span> <span class="token function">onLogin</span><span class="token punctuation">(</span><span class="token parameter"><span class="token punctuation">{</span>
	success<span class="token punctuation">,</span>
	params <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">,</span>
	isAgin <span class="token operator">=</span> <span class="token boolean">false</span>
<span class="token punctuation">}</span> <span class="token operator">=</span> <span class="token punctuation">{</span><span class="token punctuation">}</span></span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token comment">// 判定对内或对外</span>
	uni<span class="token punctuation">.</span><span class="token function">login</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
		<span class="token function">success</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			params<span class="token punctuation">[</span><span class="token string">'js_code'</span><span class="token punctuation">]</span> <span class="token operator">=</span> res<span class="token punctuation">.</span>code
			console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span>
			uni<span class="token punctuation">.</span><span class="token function">request</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
				<span class="token literal-property property">url</span><span class="token operator">:</span> urlConfig<span class="token punctuation">.</span>baseUrl <span class="token operator">+</span> <span class="token string">'login'</span><span class="token punctuation">,</span>
				<span class="token literal-property property">data</span><span class="token operator">:</span> params<span class="token punctuation">,</span>
				<span class="token literal-property property">header</span><span class="token operator">:</span> <span class="token punctuation">{</span>
					<span class="token string-property property">'content-type'</span><span class="token operator">:</span> <span class="token string">'application/json'</span> <span class="token comment">// 默认值</span>
				<span class="token punctuation">}</span><span class="token punctuation">,</span>
				<span class="token function">success</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
					<span class="token comment">// 成功</span>
					<span class="token keyword">if</span> <span class="token punctuation">(</span>res<span class="token punctuation">.</span>statusCode <span class="token operator">===</span> <span class="token number">200</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
						<span class="token keyword">if</span> <span class="token punctuation">(</span>res<span class="token punctuation">.</span>data<span class="token punctuation">.</span>code <span class="token operator">===</span> hsCode<span class="token punctuation">.</span>successCode<span class="token punctuation">)</span> <span class="token punctuation">{</span>
							<span class="token keyword">const</span> data <span class="token operator">=</span> res<span class="token punctuation">.</span>data<span class="token punctuation">.</span>data
							<span class="token keyword">if</span> <span class="token punctuation">(</span>isAgin<span class="token punctuation">)</span> <span class="token punctuation">{</span>
								<span class="token keyword">if</span> <span class="token punctuation">(</span>requestMethod <span class="token operator">===</span> <span class="token string">'GET'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
									<span class="token function">requestWithGet</span><span class="token punctuation">(</span>requestInfoData<span class="token punctuation">)</span>
								<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>requestMethod <span class="token operator">===</span>
									<span class="token string">'POST'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
									<span class="token function">requestWithPost</span><span class="token punctuation">(</span>requestInfoData<span class="token punctuation">)</span>
								<span class="token punctuation">}</span>
							<span class="token punctuation">}</span>
							success <span class="token operator">&amp;&amp;</span> <span class="token function">success</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span>
						<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
							console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'wx.login:fail '</span> <span class="token operator">+</span> res<span class="token punctuation">.</span>data<span class="token punctuation">.</span>msg<span class="token punctuation">)</span>
						<span class="token punctuation">}</span>
					<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
						console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'wx.login:fail '</span> <span class="token operator">+</span> res<span class="token punctuation">.</span>errMsg<span class="token punctuation">)</span>
					<span class="token punctuation">}</span>
				<span class="token punctuation">}</span><span class="token punctuation">,</span>
				<span class="token function">fail</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
					console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'wx.login:fail '</span> <span class="token operator">+</span> res<span class="token punctuation">.</span>errMsg<span class="token punctuation">)</span>
					wx<span class="token punctuation">.</span><span class="token function">showToast</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
						<span class="token literal-property property">title</span><span class="token operator">:</span> <span class="token string">'请检查网络'</span><span class="token punctuation">,</span>
						<span class="token literal-property property">icon</span><span class="token operator">:</span> <span class="token string">'none'</span>
					<span class="token punctuation">}</span><span class="token punctuation">)</span>
				<span class="token punctuation">}</span>
			<span class="token punctuation">}</span><span class="token punctuation">)</span>
		<span class="token punctuation">}</span><span class="token punctuation">,</span>
		<span class="token function">fail</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token comment">// 失败</span>
			console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span>
			uni<span class="token punctuation">.</span><span class="token function">showToast</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
				<span class="token literal-property property">title</span><span class="token operator">:</span> <span class="token string">'请检查网络状态'</span><span class="token punctuation">,</span>
				<span class="token literal-property property">icon</span><span class="token operator">:</span> <span class="token string">'none'</span>
			<span class="token punctuation">}</span><span class="token punctuation">)</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// 深拷贝对象</span>
<span class="token keyword">function</span> <span class="token function">deepCopy</span><span class="token punctuation">(</span><span class="token parameter">obj</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">var</span> result <span class="token operator">=</span> Array<span class="token punctuation">.</span><span class="token function">isArray</span><span class="token punctuation">(</span>obj<span class="token punctuation">)</span> <span class="token operator">?</span> <span class="token punctuation">[</span><span class="token punctuation">]</span> <span class="token operator">:</span> <span class="token punctuation">{</span><span class="token punctuation">}</span><span class="token punctuation">;</span>
	<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">var</span> key <span class="token keyword">in</span> obj<span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span>obj<span class="token punctuation">.</span><span class="token function">hasOwnProperty</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
			<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">===</span> <span class="token string">'object'</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				result<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token function">deepCopy</span><span class="token punctuation">(</span>obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//递归复制</span>
			<span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
				result<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">=</span> obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span><span class="token punctuation">;</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">return</span> result<span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">/**
 * DELETE请求
 */</span>
<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">requestWithDelete</span><span class="token punctuation">(</span><span class="token parameter">requestInfo</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	requestInfoData <span class="token operator">=</span> <span class="token function">deepCopy</span><span class="token punctuation">(</span>requestInfo<span class="token punctuation">)</span>
	requestMethod <span class="token operator">=</span> <span class="token string">'DELETE'</span>
	<span class="token function">request</span><span class="token punctuation">(</span>requestInfo<span class="token punctuation">.</span>apiName<span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>params<span class="token punctuation">,</span> <span class="token string">&quot;DELETE&quot;</span><span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>success<span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>fail<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">/**
 * put请求
 */</span>
<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">requestWithPut</span><span class="token punctuation">(</span><span class="token parameter">requestInfo</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	requestInfoData <span class="token operator">=</span> <span class="token function">deepCopy</span><span class="token punctuation">(</span>requestInfo<span class="token punctuation">)</span>
	requestMethod <span class="token operator">=</span> <span class="token string">'PUT'</span>
	<span class="token function">request</span><span class="token punctuation">(</span>requestInfo<span class="token punctuation">.</span>apiName<span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>params<span class="token punctuation">,</span> <span class="token string">&quot;PUT&quot;</span><span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>success<span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>fail<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">/**
 * post请求
 */</span>
<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">requestWithPost</span><span class="token punctuation">(</span><span class="token parameter">requestInfo</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	requestInfoData <span class="token operator">=</span> <span class="token function">deepCopy</span><span class="token punctuation">(</span>requestInfo<span class="token punctuation">)</span>
	requestMethod <span class="token operator">=</span> <span class="token string">'POST'</span>
	<span class="token function">request</span><span class="token punctuation">(</span>requestInfo<span class="token punctuation">.</span>apiName<span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>params<span class="token punctuation">,</span> <span class="token string">&quot;POST&quot;</span><span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>success<span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>fail<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">/**
 * get请求
 */</span>
<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">requestWithGet</span><span class="token punctuation">(</span><span class="token parameter">requestInfo</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	requestInfoData <span class="token operator">=</span> <span class="token function">deepCopy</span><span class="token punctuation">(</span>requestInfo<span class="token punctuation">)</span>
	requestMethod <span class="token operator">=</span> <span class="token string">'GET'</span>
	<span class="token function">request</span><span class="token punctuation">(</span>requestInfo<span class="token punctuation">.</span>apiName<span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>params<span class="token punctuation">,</span> <span class="token string">&quot;GET&quot;</span><span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>success<span class="token punctuation">,</span> requestInfo<span class="token punctuation">.</span>fail<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token comment">// 上传图片</span>
<span class="token comment">/**
 * 上传图片传参
 * options: {
 *  image: [],        必须，图片数据 string[]
 *  params: {},       必须，接口参数
 *  success: ()=&gt;{},  成功回调
 *  fail: ()=&gt;{},     失败回调
 * }
 */</span>
<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">uploadImage</span><span class="token punctuation">(</span><span class="token parameter">options</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">'请求参数----&gt;'</span> <span class="token operator">+</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">stringify</span><span class="token punctuation">(</span>options<span class="token punctuation">.</span>params<span class="token punctuation">)</span><span class="token punctuation">)</span>
	<span class="token keyword">let</span> url <span class="token operator">=</span> urlConfig<span class="token punctuation">.</span>baseUrl <span class="token operator">+</span> <span class="token string">'api/upload'</span>
	<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> options<span class="token punctuation">.</span>image <span class="token operator">===</span> <span class="token string">'undefined'</span> <span class="token operator">||</span> options<span class="token punctuation">.</span>image<span class="token punctuation">.</span>length <span class="token operator">===</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token function">requestWithPost</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
			url<span class="token punctuation">,</span>
			<span class="token literal-property property">params</span><span class="token operator">:</span> options<span class="token punctuation">.</span>params<span class="token punctuation">,</span>
			<span class="token function-variable function">success</span><span class="token operator">:</span> <span class="token parameter">data</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
				wx<span class="token punctuation">.</span><span class="token function">hideLoading</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
				options<span class="token punctuation">.</span>success <span class="token operator">&amp;&amp;</span> options<span class="token punctuation">.</span><span class="token function">success</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>
			<span class="token punctuation">}</span><span class="token punctuation">,</span>
			<span class="token function">fail</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				wx<span class="token punctuation">.</span><span class="token function">hideLoading</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
				options<span class="token punctuation">.</span>fail <span class="token operator">&amp;&amp;</span> options<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span>
		<span class="token keyword">return</span>
	<span class="token punctuation">}</span>
	<span class="token keyword">let</span> callUploadApi <span class="token operator">=</span> <span class="token number">0</span>

	<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> options<span class="token punctuation">.</span>image<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
		<span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token keyword">typeof</span> options<span class="token punctuation">.</span>params<span class="token punctuation">.</span>sortNum <span class="token operator">===</span> <span class="token string">'undefined'</span><span class="token punctuation">)</span> options<span class="token punctuation">.</span>params<span class="token punctuation">.</span>sortNum <span class="token operator">=</span> <span class="token number">0</span>
		options<span class="token punctuation">.</span>params<span class="token punctuation">.</span>Sort <span class="token operator">=</span> options<span class="token punctuation">.</span>params<span class="token punctuation">.</span>sortNum <span class="token operator">+</span> <span class="token punctuation">(</span>i <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span>
		<span class="token comment">// setTimeout(() =&gt; {</span>
		wx<span class="token punctuation">.</span><span class="token function">uploadFile</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
			<span class="token literal-property property">url</span><span class="token operator">:</span> url <span class="token operator">+</span> arugment<span class="token punctuation">,</span> <span class="token comment">//仅为示例，非真实的接口地址</span>
			<span class="token literal-property property">filePath</span><span class="token operator">:</span> options<span class="token punctuation">.</span>image<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">,</span>
			<span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'file'</span><span class="token punctuation">,</span>
			<span class="token literal-property property">header</span><span class="token operator">:</span> <span class="token punctuation">{</span>
				<span class="token string-property property">'content-type'</span><span class="token operator">:</span> <span class="token string">'multipart/form-data'</span><span class="token punctuation">,</span>
				<span class="token string-property property">&quot;Cookie&quot;</span><span class="token operator">:</span> <span class="token string">&quot;ASP.NET_SessionId=&quot;</span> <span class="token operator">+</span> wx<span class="token punctuation">.</span><span class="token function">getStorageSync</span><span class="token punctuation">(</span><span class="token string">&quot;sessionId&quot;</span><span class="token punctuation">)</span>
			<span class="token punctuation">}</span><span class="token punctuation">,</span>
			<span class="token literal-property property">formData</span><span class="token operator">:</span> options<span class="token punctuation">.</span>params<span class="token punctuation">,</span>
			<span class="token function">success</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				wx<span class="token punctuation">.</span><span class="token function">hideLoading</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
				<span class="token keyword">const</span> data <span class="token operator">=</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span>res<span class="token punctuation">.</span>data<span class="token punctuation">)</span>
				callUploadApi<span class="token operator">++</span>
				<span class="token keyword">if</span> <span class="token punctuation">(</span>callUploadApi <span class="token operator">===</span> options<span class="token punctuation">.</span>image<span class="token punctuation">.</span>length<span class="token punctuation">)</span> <span class="token punctuation">{</span>
					options<span class="token punctuation">.</span>success <span class="token operator">&amp;&amp;</span> options<span class="token punctuation">.</span><span class="token function">success</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>
				<span class="token punctuation">}</span>
			<span class="token punctuation">}</span><span class="token punctuation">,</span>
			<span class="token function">fail</span><span class="token punctuation">(</span><span class="token parameter">res</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
				wx<span class="token punctuation">.</span><span class="token function">hideLoading</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
				options<span class="token punctuation">.</span>fail <span class="token operator">&amp;&amp;</span> options<span class="token punctuation">.</span><span class="token function">fail</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>

module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
	requestWithGet<span class="token punctuation">,</span>
	requestWithPost<span class="token punctuation">,</span>
	requestWithPut<span class="token punctuation">,</span>
	requestWithDelete<span class="token punctuation">,</span>
<span class="token punctuation">}</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br><span class="line-number">81</span><br><span class="line-number">82</span><br><span class="line-number">83</span><br><span class="line-number">84</span><br><span class="line-number">85</span><br><span class="line-number">86</span><br><span class="line-number">87</span><br><span class="line-number">88</span><br><span class="line-number">89</span><br><span class="line-number">90</span><br><span class="line-number">91</span><br><span class="line-number">92</span><br><span class="line-number">93</span><br><span class="line-number">94</span><br><span class="line-number">95</span><br><span class="line-number">96</span><br><span class="line-number">97</span><br><span class="line-number">98</span><br><span class="line-number">99</span><br><span class="line-number">100</span><br><span class="line-number">101</span><br><span class="line-number">102</span><br><span class="line-number">103</span><br><span class="line-number">104</span><br><span class="line-number">105</span><br><span class="line-number">106</span><br><span class="line-number">107</span><br><span class="line-number">108</span><br><span class="line-number">109</span><br><span class="line-number">110</span><br><span class="line-number">111</span><br><span class="line-number">112</span><br><span class="line-number">113</span><br><span class="line-number">114</span><br><span class="line-number">115</span><br><span class="line-number">116</span><br><span class="line-number">117</span><br><span class="line-number">118</span><br><span class="line-number">119</span><br><span class="line-number">120</span><br><span class="line-number">121</span><br><span class="line-number">122</span><br><span class="line-number">123</span><br><span class="line-number">124</span><br><span class="line-number">125</span><br><span class="line-number">126</span><br><span class="line-number">127</span><br><span class="line-number">128</span><br><span class="line-number">129</span><br><span class="line-number">130</span><br><span class="line-number">131</span><br><span class="line-number">132</span><br><span class="line-number">133</span><br><span class="line-number">134</span><br><span class="line-number">135</span><br><span class="line-number">136</span><br><span class="line-number">137</span><br><span class="line-number">138</span><br><span class="line-number">139</span><br><span class="line-number">140</span><br><span class="line-number">141</span><br><span class="line-number">142</span><br><span class="line-number">143</span><br><span class="line-number">144</span><br><span class="line-number">145</span><br><span class="line-number">146</span><br><span class="line-number">147</span><br><span class="line-number">148</span><br><span class="line-number">149</span><br><span class="line-number">150</span><br><span class="line-number">151</span><br><span class="line-number">152</span><br><span class="line-number">153</span><br><span class="line-number">154</span><br><span class="line-number">155</span><br><span class="line-number">156</span><br><span class="line-number">157</span><br><span class="line-number">158</span><br><span class="line-number">159</span><br><span class="line-number">160</span><br><span class="line-number">161</span><br><span class="line-number">162</span><br><span class="line-number">163</span><br><span class="line-number">164</span><br><span class="line-number">165</span><br><span class="line-number">166</span><br><span class="line-number">167</span><br><span class="line-number">168</span><br><span class="line-number">169</span><br><span class="line-number">170</span><br><span class="line-number">171</span><br><span class="line-number">172</span><br><span class="line-number">173</span><br><span class="line-number">174</span><br><span class="line-number">175</span><br><span class="line-number">176</span><br><span class="line-number">177</span><br><span class="line-number">178</span><br><span class="line-number">179</span><br><span class="line-number">180</span><br><span class="line-number">181</span><br><span class="line-number">182</span><br><span class="line-number">183</span><br><span class="line-number">184</span><br><span class="line-number">185</span><br><span class="line-number">186</span><br><span class="line-number">187</span><br><span class="line-number">188</span><br><span class="line-number">189</span><br><span class="line-number">190</span><br><span class="line-number">191</span><br><span class="line-number">192</span><br><span class="line-number">193</span><br><span class="line-number">194</span><br><span class="line-number">195</span><br><span class="line-number">196</span><br><span class="line-number">197</span><br><span class="line-number">198</span><br><span class="line-number">199</span><br><span class="line-number">200</span><br><span class="line-number">201</span><br><span class="line-number">202</span><br><span class="line-number">203</span><br><span class="line-number">204</span><br><span class="line-number">205</span><br><span class="line-number">206</span><br><span class="line-number">207</span><br><span class="line-number">208</span><br><span class="line-number">209</span><br><span class="line-number">210</span><br><span class="line-number">211</span><br><span class="line-number">212</span><br><span class="line-number">213</span><br><span class="line-number">214</span><br><span class="line-number">215</span><br><span class="line-number">216</span><br><span class="line-number">217</span><br><span class="line-number">218</span><br><span class="line-number">219</span><br><span class="line-number">220</span><br><span class="line-number">221</span><br><span class="line-number">222</span><br><span class="line-number">223</span><br><span class="line-number">224</span><br><span class="line-number">225</span><br><span class="line-number">226</span><br><span class="line-number">227</span><br><span class="line-number">228</span><br><span class="line-number">229</span><br><span class="line-number">230</span><br><span class="line-number">231</span><br><span class="line-number">232</span><br><span class="line-number">233</span><br><span class="line-number">234</span><br><span class="line-number">235</span><br><span class="line-number">236</span><br><span class="line-number">237</span><br><span class="line-number">238</span><br><span class="line-number">239</span><br><span class="line-number">240</span><br><span class="line-number">241</span><br><span class="line-number">242</span><br><span class="line-number">243</span><br><span class="line-number">244</span><br><span class="line-number">245</span><br><span class="line-number">246</span><br><span class="line-number">247</span><br><span class="line-number">248</span><br><span class="line-number">249</span><br><span class="line-number">250</span><br><span class="line-number">251</span><br><span class="line-number">252</span><br><span class="line-number">253</span><br><span class="line-number">254</span><br><span class="line-number">255</span><br><span class="line-number">256</span><br><span class="line-number">257</span><br><span class="line-number">258</span><br><span class="line-number">259</span><br><span class="line-number">260</span><br><span class="line-number">261</span><br><span class="line-number">262</span><br></div></div><h3 id="publicinferface-js"><a href="#publicinferface-js" class="header-anchor">#</a> publicInferface.js</h3> <blockquote><p>进行模块化的接口管理，你当前接口属于哪个模块，你就放在哪个模块里面。这样更方便对接口进行管理，后期也更好维护。该文件内的接口为基本模拟，实际开发按需添加接口即可。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">// 公共接口调用</span>
<span class="token comment">// 调用封装接口的文件，下面的所有请求都使用封装好的接口</span>
<span class="token keyword">import</span> hs <span class="token keyword">from</span> <span class="token string">'./networkRequestManage'</span>
<span class="token keyword">import</span> hsCode <span class="token keyword">from</span> <span class="token string">'../config/statusCode.js'</span>
<span class="token keyword">import</span> storage <span class="token keyword">from</span> <span class="token string">'../config/storage'</span>
<span class="token keyword">import</span> urlConfig <span class="token keyword">from</span> <span class="token string">'@/config/urlConfig.js'</span>

<span class="token comment">/**
 * GET接口请求
 */</span>
<span class="token keyword">function</span> <span class="token function">getTranslation</span><span class="token punctuation">(</span><span class="token parameter">key</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve<span class="token punctuation">,</span> reject</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
		hs<span class="token punctuation">.</span><span class="token function">requestWithPost</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
			<span class="token literal-property property">apiName</span><span class="token operator">:</span> <span class="token string">'api/common/GetTranslation'</span><span class="token punctuation">,</span>
            <span class="token literal-property property">params</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token comment">// 没有参数可以直接不传参</span>
				key
			<span class="token punctuation">}</span><span class="token punctuation">,</span>
			<span class="token function-variable function">success</span><span class="token operator">:</span> <span class="token parameter">data</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
				<span class="token function">resolve</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>
			<span class="token punctuation">}</span><span class="token punctuation">,</span>
			<span class="token function-variable function">fail</span><span class="token operator">:</span> <span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
				<span class="token function">reject</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">/**
 * POST接口请求
 */</span>
<span class="token keyword">function</span> <span class="token function">postTranslation</span><span class="token punctuation">(</span><span class="token parameter">params</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve<span class="token punctuation">,</span> reject</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
		hs<span class="token punctuation">.</span><span class="token function">requestWithGet</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
			<span class="token literal-property property">apiName</span><span class="token operator">:</span> <span class="token string">'api/common/PostTranslation'</span><span class="token punctuation">,</span>
            params<span class="token punctuation">,</span>
			<span class="token function-variable function">success</span><span class="token operator">:</span> <span class="token parameter">data</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
				<span class="token function">resolve</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>
			<span class="token punctuation">}</span><span class="token punctuation">,</span>
			<span class="token function-variable function">fail</span><span class="token operator">:</span> <span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
				<span class="token function">reject</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">/**
 * PUT接口请求
 */</span>
<span class="token keyword">function</span> <span class="token function">putTranslation</span><span class="token punctuation">(</span><span class="token parameter">key</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve<span class="token punctuation">,</span> reject</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
		hs<span class="token punctuation">.</span><span class="token function">requestWithPut</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
			<span class="token literal-property property">apiName</span><span class="token operator">:</span> <span class="token string">'api/common/PutTranslation'</span><span class="token punctuation">,</span>
            <span class="token literal-property property">params</span><span class="token operator">:</span> <span class="token punctuation">{</span>
				<span class="token literal-property property">key</span><span class="token operator">:</span>key<span class="token punctuation">,</span>
			<span class="token punctuation">}</span><span class="token punctuation">,</span>
			<span class="token function-variable function">success</span><span class="token operator">:</span> <span class="token parameter">data</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
				<span class="token function">resolve</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>
			<span class="token punctuation">}</span><span class="token punctuation">,</span>
			<span class="token function-variable function">fail</span><span class="token operator">:</span> <span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
				<span class="token function">reject</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">/**
 * DELETE接口请求
 */</span>
<span class="token keyword">function</span> <span class="token function">getTranslation</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Promise</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token parameter">resolve<span class="token punctuation">,</span> reject</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
		hs<span class="token punctuation">.</span><span class="token function">requestWithDelete</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
			<span class="token literal-property property">apiName</span><span class="token operator">:</span> <span class="token string">'api/common/DeleteTranslation'</span><span class="token punctuation">,</span>
			<span class="token function-variable function">success</span><span class="token operator">:</span> <span class="token parameter">data</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
				<span class="token function">resolve</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span>
			<span class="token punctuation">}</span><span class="token punctuation">,</span>
			<span class="token function-variable function">fail</span><span class="token operator">:</span> <span class="token parameter">res</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
				<span class="token function">reject</span><span class="token punctuation">(</span>res<span class="token punctuation">)</span>
			<span class="token punctuation">}</span>
		<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>

<span class="token comment">// 导出接口</span>
module<span class="token punctuation">.</span>exports <span class="token operator">=</span> <span class="token punctuation">{</span>
	getTranslation<span class="token punctuation">,</span>
    postTranslation<span class="token punctuation">,</span>
    putTranslation<span class="token punctuation">,</span>
    getTranslation<span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br><span class="line-number">35</span><br><span class="line-number">36</span><br><span class="line-number">37</span><br><span class="line-number">38</span><br><span class="line-number">39</span><br><span class="line-number">40</span><br><span class="line-number">41</span><br><span class="line-number">42</span><br><span class="line-number">43</span><br><span class="line-number">44</span><br><span class="line-number">45</span><br><span class="line-number">46</span><br><span class="line-number">47</span><br><span class="line-number">48</span><br><span class="line-number">49</span><br><span class="line-number">50</span><br><span class="line-number">51</span><br><span class="line-number">52</span><br><span class="line-number">53</span><br><span class="line-number">54</span><br><span class="line-number">55</span><br><span class="line-number">56</span><br><span class="line-number">57</span><br><span class="line-number">58</span><br><span class="line-number">59</span><br><span class="line-number">60</span><br><span class="line-number">61</span><br><span class="line-number">62</span><br><span class="line-number">63</span><br><span class="line-number">64</span><br><span class="line-number">65</span><br><span class="line-number">66</span><br><span class="line-number">67</span><br><span class="line-number">68</span><br><span class="line-number">69</span><br><span class="line-number">70</span><br><span class="line-number">71</span><br><span class="line-number">72</span><br><span class="line-number">73</span><br><span class="line-number">74</span><br><span class="line-number">75</span><br><span class="line-number">76</span><br><span class="line-number">77</span><br><span class="line-number">78</span><br><span class="line-number">79</span><br><span class="line-number">80</span><br><span class="line-number">81</span><br><span class="line-number">82</span><br><span class="line-number">83</span><br><span class="line-number">84</span><br><span class="line-number">85</span><br><span class="line-number">86</span><br><span class="line-number">87</span><br><span class="line-number">88</span><br><span class="line-number">89</span><br></div></div><h2 id="main-js-配置全局导入"><a href="#main-js-配置全局导入" class="header-anchor">#</a> main.js - 配置全局导入</h2> <blockquote><p>在main.js中对配置文件全局导入，我们调用接口的时候就可以直接调用，而不用每次都import导入相关文件。</p> <ul><li><p><code>import * as publicInterface from './networking/publicInferface.js'</code></p> <p>导入接口 js 为下面的原型定义做准备</p></li> <li><p><code>Vue.prototype.$publicInterface = publicInterface</code></p> <p>在vue项目main.js文件中通过上述方法，可以原型上定义它们使其在每个 Vue 的实例中可用，为后面我们在页面中的导入做准备</p></li></ul></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">import</span> App <span class="token keyword">from</span> <span class="token string">'./App'</span>

<span class="token comment">// 公共接口</span>
<span class="token keyword">import</span> <span class="token operator">*</span> <span class="token keyword">as</span> publicInterface <span class="token keyword">from</span> <span class="token string">'./networking/publicInferface.js'</span>
<span class="token keyword">import</span> storage <span class="token keyword">from</span> <span class="token string">'config/storage.js'</span> <span class="token comment">// 缓存文件</span>
<span class="token keyword">import</span> tools <span class="token keyword">from</span> <span class="token string">'utils/tools.js'</span> <span class="token comment">// 工具文件</span>

<span class="token comment">// 定义全局</span>
<span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>$publicInterface <span class="token operator">=</span> publicInterface
<span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>$storage <span class="token operator">=</span> storage
<span class="token class-name">Vue</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>$tools <span class="token operator">=</span> tools

<span class="token comment">// #ifndef VUE3</span>
<span class="token keyword">import</span> Vue <span class="token keyword">from</span> <span class="token string">'vue'</span>
Vue<span class="token punctuation">.</span>config<span class="token punctuation">.</span>productionTip <span class="token operator">=</span> <span class="token boolean">false</span>
App<span class="token punctuation">.</span>mpType <span class="token operator">=</span> <span class="token string">'app'</span>
<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">Vue</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
	<span class="token operator">...</span>App
<span class="token punctuation">}</span><span class="token punctuation">)</span>
app<span class="token punctuation">.</span><span class="token function">$mount</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
<span class="token comment">// #endif</span>

<span class="token comment">// #ifdef VUE3</span>
<span class="token keyword">import</span> <span class="token punctuation">{</span>
	createSSRApp
<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'vue'</span>
<span class="token keyword">export</span> <span class="token keyword">function</span> <span class="token function">createApp</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
	<span class="token keyword">const</span> app <span class="token operator">=</span> <span class="token function">createSSRApp</span><span class="token punctuation">(</span>App<span class="token punctuation">)</span>
	<span class="token keyword">return</span> <span class="token punctuation">{</span>
		app
	<span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token comment">// #endif</span>

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br><span class="line-number">28</span><br><span class="line-number">29</span><br><span class="line-number">30</span><br><span class="line-number">31</span><br><span class="line-number">32</span><br><span class="line-number">33</span><br><span class="line-number">34</span><br></div></div><h2 id="publicinferface-vue-页面调用接口"><a href="#publicinferface-vue-页面调用接口" class="header-anchor">#</a> publicInferface.vue - 页面调用接口</h2> <blockquote><p>接下来介绍页面中如何引用，在 main.js 中定义后，导入就变得很简单了。</p> <p>根据在接口文档定义的参数，需要调用对应功能模块下对应函数即可。只要你在接口页面处理好了请求类型与参数传递格式，就只需要关注传递的参数。</p></blockquote> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token comment">/**
 * get请求：
 * $publicInferface：注意你在 main.js 定义的名称
 * getTranslation：注意你在 publicInferface.js 接口页面定义的函数名，一定不能重复
 */</span>
<span class="token keyword">this</span><span class="token punctuation">.</span>$publicInferface<span class="token punctuation">.</span><span class="token function">getTranslation</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span>
	<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
    	<span class="token comment">// 最后在回调里对返回数据进行处理即可</span>
		console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
		console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>

<span class="token comment">/**
 * post请求：
 * @params Object
 * 格式和get请求基本都是一样的，只有参数改变
 */</span>
<span class="token keyword">this</span><span class="token punctuation">.</span>$publicInferface<span class="token punctuation">.</span><span class="token function">postTranslation</span><span class="token punctuation">(</span>params<span class="token punctuation">)</span>
	<span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
		console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
	<span class="token punctuation">.</span><span class="token function">catch</span><span class="token punctuation">(</span><span class="token parameter">e</span> <span class="token operator">=&gt;</span> <span class="token punctuation">{</span>
		console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span>
	<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br></div></div></div></section> <footer class="page-edit"><!----> <!----></footer> <!----> <div class="comments-wrapper"><!----></div></main></div> <!----></div> <ul class="sub-sidebar sub-sidebar-wrapper" style="width:0;" data-v-b57cc07c data-v-7dd95ae2></ul></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/blog/assets/js/app.c8bfb5c3.js" defer></script><script src="/blog/assets/js/3.08e74d92.js" defer></script><script src="/blog/assets/js/1.f96517fa.js" defer></script><script src="/blog/assets/js/20.5d2b0628.js" defer></script>
  </body>
</html>
